﻿namespace SERFLITEMAX20.WinUI.Controls
{
    using System;
    using System.Collections;
    using System.Windows.Forms;

    public class ListViewTextSort : IComparer
    {
        private bool m_ascending;
        private int m_column;

        public ListViewTextSort(int sortColumn, bool ascending)
        {
            this.m_column = sortColumn;
            this.m_ascending = ascending;
        }

        public int Compare(object lhs, object rhs)
        {
            ListViewItem item = lhs as ListViewItem;
            ListViewItem item2 = rhs as ListViewItem;
            if ((item == null) || (item2 == null))
            {
                return 0;
            }
            ListViewItem.ListViewSubItemCollection subItems = item.SubItems;
            ListViewItem.ListViewSubItemCollection items2 = item2.SubItems;
            string str = (subItems.Count > this.m_column) ? subItems[this.m_column].Text : string.Empty;
            string strB = (items2.Count > this.m_column) ? items2[this.m_column].Text : string.Empty;
            int num = 0;
            if ((str.Length == 0) || (strB.Length == 0))
            {
                num = str.CompareTo(strB);
            }
            else
            {
                num = this.OnCompare(str, strB);
            }
            if (!this.m_ascending)
            {
                num = -num;
            }
            return num;
        }

        protected virtual int OnCompare(string lhs, string rhs)
        {
            return string.Compare(lhs, rhs, false);
        }
    }
}

